<template>
	<view>
		<van-search
		  v-model="searchText"
		  placeholder="请输入搜索关键词"
		  show-action
		 shape="round"
		  @search="onSearch"
		  @cancel="onCancel"
		/>
	<view class="my-page-content">
		
		<view  class="flex-between grey-tips mb20">
			<view>历史记录</view>
			<view>
				<uni-icons @click="deleteRecord" color="#C4C4C4" class="del" type="trash" size="22"></uni-icons>
			</view>
		</view>
		<view class="record-list-con">
			<view @click="goPage(item)"  v-for="(item, index) in recordList" :key="index">
				<van-icon color="#C4C4C4" size="14" class="record-icon" name="clock-o" /> {{item}}
			</view>
		</view>
		
		</view>
	</view>
</template>

<script>
	import store from '../store/index.js'
	export default {
		data() {
			return {
				searchText: '',
				recordList: this.$getStorage('serachRecordlist') || []
			}
		},
		methods: {
			onSearch(e) {
				const searchText = e.detail;
				store.state.searchData.keywords = searchText;
				if(this.recordList.length < 5) {
					this.recordList.unshift(searchText);
				} else {
					this.recordList.unshift(searchText);
					this.recordList.pop();
				}
				this.$setStorage('serachRecordlist', this.recordList);
				uni.navigateBack();
				
			},
			goPage(item) {
				store.state.searchData.keywords = item;
				uni.navigateBack();
			},
			onCancel() {
				uni.navigateBack();
				// this.$goPage(2, '/pages/index/index');
			},
			deleteRecord() {
				this.$setStorage('serachRecordlist', '');
				this.recordList = [];
			}
		}
	}
</script>

<style scoped lang="scss">
	.record-list-con {
		font-weight: 400;
		font-size: 27rpx;
		color: #000000;
		line-height: 40rpx;
			
		.record-icon {
			margin-right: 10rpx ;
			vertical-align: middle;
		}
	}
</style>